var uniquePathsWithObstacles = function(obstacleGrid) {
    let m = obstacleGrid.length;
    let n = obstacleGrid[0].length;
    const memo = new Array(m).fill(0).map(() => new Array(n).fill(-1));
    if(obstacleGrid[0][0]===1){
        return 0
    }
    function dfs(i,j){
        if(i===0&&j===0){
            return 1;
        }
        if(i<0||j<0||obstacleGrid[i][j]===1){
            return 0;
        }
        if(memo[i][j]!=-1){
            return memo[i][j]
        }
        return memo[i][j]=dfs(i-1,j)+dfs(i,j-1)
    }
    return dfs(m-1,n-1)
}